import {HttpService} from "./HttpService";
import {mc_dialog} from "./model/mc_dialog";
import {Input, Output} from "@angular/core";
/**
 * Created by ybjaa on 2017/6/1.
 */

declare let $:any;

export class BaseComponent extends HttpService{


    protected dialog:mc_dialog=new mc_dialog();


    /**
     * 局部遮罩层的HTML
     * @type {string}
     */
    public part_mask:string=
        //"<div  class=\"part-mask\"><div><div class=\"progress-bar progress-bar-striped active\" role=\"progressbar\"></div></div></div>";
        `<div  class="part-mask">
            <div class="progress-bar progress-bar-striped active" role="progressbar"></div>
         </div>`;

    /**
     * 输出错误信息
     * @type {string}
     * @private
     */
    _message:string="";

    get getMessage(){

        if(this._message&&this._message.includes("\r\n")){
            return "<p>"+ (this._message||"").split("\r\n").join("</p><p>")+"</p>"
        }

        return this._message||"";
    }

    protected setMessage(ex:any,message:string=null,isShowDialog:boolean=false):void{
        if(!this) return;

        this.isAjax=false;

        if(ex&&ex.message) this._message=ex.message;
        if(ex&&ex.statusText ) this._message="status:"+ex.status+"\r\n text:"+ex.statusText;
        if(message) {
            this._message=(this._message||"");
            this._message+= this._message==""?message:this._message+"\r\n"+message;
        }

        if(isShowDialog){
            this.dialog.message=this._message;
            this.dialog.dangerShow();
        }


    }












}